"""
准确率计算
"""
import os.path
import json

from answer.test import Answer


def get_right_num():
    path = r"../../media/result/result.txt"
    with open(path, "r") as f:  # 打开文件
        data = f.read()  # 读取文件
    data = json.loads(data)
    # print(data)
    return data


def get_answer_data(path):
    err_list = []
    right_list = get_right_num()
    answer = Answer(path)
    ans_list, texts, file_name, points_range_name, points_threshold_name, answer_result_name = answer.start()
    print("ans_list==============", ans_list)
    for right in right_list:
        right_key = int(right['number'])
        is_in = False
        is_right = False
        for ans in ans_list:
            # print("=================", right_key, ans)
            if right_key == ans['num']:
                is_in = True
                if right['answer'] == ','.join(ans['ans']):
                    is_right = True
                else:
                    err_list.append((right_key, right['answer'], ans['ans']))
                break
        if not is_in:
            err_list.append((right_key, 'none'))
    print("err_list============",len(err_list),err_list)
    return err_list


if __name__ == '__main__':
    get_answer_data('../../media/test/1622170544478.jpg')
